if (!exports) {
    var exports = {}
} (function (e, c, f) {
    var a = c;
    if (!a) {
        var a = {}
    } (function (g, h) {
        if (!g.browser) {
            g.browser = {}
        }
        g.browser.extension = {
            sendRequest: function (j, i) {
                if (typeof i == "undefined") {
                    i = function () { }
                }
                chrome.extension.sendRequest(j, i)
            },
            onRequest: {
                addListener: function (i) {
                    chrome.extension.onRequest.addListener(i)
                },
                removeListener: function (i) {
                    chrome.extension.onRequest.removeListener(i)
                }
            },
            getURL: function (i) {
                return chrome.extension.getURL(i || "")
            }
        }
    })(a);
    c.console = {
        debug: function (g) {
            c.browser.extension.sendRequest({
                topic: "log_message",
                message: g
            })
        }
    };
    if (!a) {
        var a = {}
    } (function (g, h) {
        g.PageCache = function (k, j, i) {
            if (i) {
                return new g.PageCache.async(k, j)
            } else {
                return new g.PageCache.sync(k, j)
            }
        };
        g.PageCache.sync = function (j, i) {
            if (arguments.length == 0) {
                return
            }
            this.page_no = -1;
            this.pager_total_pages = h;
            this.pager_total_entries = h;
            this.cache = [];
            if (typeof j == "function") {
                this.generator = j;
                this.generator_finished = false
            } else {
                this.pager = j.get;
                this.pager_page_size = j.PageSize
            }
            this.page_size = i.PageSize
        };
        g.PageCache.sync.prototype = {
            next: function () {
                var i = [];
                if (this.hasNext()) {
                    this.page_no++;
                    i = this.get(this.page_no + 1).Entries;
                    if (i.length == 0) {
                        this.page_no--
                    }
                }
                return i
            },
            previous: function () {
                var i = [];
                if (this.hasPrevious()) {
                    this.page_no--;
                    i = this.get(this.page_no + 1).Entries
                }
                return i
            },
            hasNext: function () {
                var i = this.getTotalPages();
                return isNaN(i) ? true : this.page_no + 1 < i
            },
            hasPrevious: function () {
                return this.page_no > 0
            },
            getTotalPages: function () {
                var i;
                if (this.pager) {
                    if (typeof this.pager_total_pages == "undefined") {
                        return NaN
                    }
                    if (typeof this.pager_total_entries == "undefined") {
                        if (typeof this.cache[this.pager_total_pages - 1] != "undefined") {
                            i = (this.pager_total_pages - 1) * this.pager_page_size + this.cache[this.pager_total_pages - 1].Entries.length
                        } else {
                            i = this.pager_total_pages * this.pager_page_size
                        }
                    } else {
                        i = this.pager_total_entries
                    }
                } else {
                    if (!this.generator_finished) {
                        return NaN
                    } else {
                        i = this.cache.length
                    }
                }
                return Math.ceil(i / this.page_size)
            },
            get: function (r) {
                r = parseInt(r);
                if (isNaN(r) || r < 1) {
                    r = 1
                }
                var q = [];
                var j = (r - 1) * this.page_size;
                var k = r * this.page_size;
                if (this.pager) {
                    var p = Math.floor(j / this.pager_page_size);
                    var t = Math.ceil(k / this.pager_page_size);
                    for (var n = p; n < t; n++) {
                        if (typeof this.cache[n] == "undefined") {
                            this.cache[n] = this.pager(n + 1)
                        }
                        var l = this.pager_page_size * n;
                        var s = l >= j ? 0 : j - l;
                        var m = l + this.pager_page_size > k ? k - l : this.pager_page_size;
                        q.push.apply(q, this.cache[n].Entries.slice(s, m));
                        if (typeof this.pager_total_pages == "undefined") {
                            this.pager_total_pages = this.cache[n].TotalPages
                        }
                        t = Math.min(t, this.pager_total_pages)
                    }
                    if (typeof this.cache[p] != "undefined" && this.cache[p].TotalEntries) {
                        this.pager_total_entries = this.cache[p].TotalEntries
                    }
                } else {
                    var o;
                    while (!this.generator_finished && this.cache.length < k) {
                        o = this.generator();
                        if (o.length == 0) {
                            this.generator_finished = true
                        }
                        this.cache.push.apply(this.cache, o)
                    }
                    q = this.cache.slice(j, k)
                }
                return {
                    TotalPages: this.getTotalPages(),
                    Entries: q
                }
            },
            reset: function () {
                this.page_no = -1
            }
        };
        g.PageCache.async = function (j, i) {
            g.PageCache.sync.call(this, j, i)
        };
        g.PageCache.async.prototype = new g.PageCache.sync();
        g.PageCache.async.prototype.constructor = g.PageCache.async;
        g.PageCache.async.prototype.next = function (j) {
            if (this.hasNext()) {
                this.page_no++;
                var i = this;
                this.get(this.page_no + 1, function (l) {
                    var k = l.Entries;
                    if (k.length == 0) {
                        i.page_no--
                    }
                    j(k)
                })
            } else {
                j([])
            }
        };
        g.PageCache.async.prototype.previous = function (i) {
            if (this.hasPrevious()) {
                this.page_no--;
                this.get(this.page_no + 1, function (j) {
                    i(j.Entries)
                })
            } else {
                i([])
            }
        };
        g.PageCache.async.prototype.get = function (o, r) {
            var s = this;
            o = parseInt(o);
            if (isNaN(o) || o < 1) {
                o = 1
            }
            var i = (o - 1) * this.page_size;
            var l = o * this.page_size;
            var n = [];
            var p = function () {
                r({
                    TotalPages: s.getTotalPages(),
                    Entries: n
                }, o)
            };
            if (this.pager) {
                var m = Math.floor(i / this.pager_page_size);
                var q = Math.ceil(l / this.pager_page_size);
                var j = function (v, u) {
                    if (v >= q) {
                        if (typeof s.cache[m] != "undefined" && s.cache[m].TotalEntries) {
                            s.pager_total_entries = s.cache[m].TotalEntries
                        }
                        p();
                        return
                    }
                    var t = function (w, y) {
                        w = w - 1;
                        s.cache[w] = y;
                        var A = s.pager_page_size * w;
                        var x = A >= i ? 0 : i - A;
                        var z = A + s.pager_page_size > l ? l - A : s.pager_page_size;
                        u.push.apply(u, s.cache[w].Entries.slice(x, z));
                        if (typeof s.pager_total_pages == "undefined") {
                            s.pager_total_pages = s.cache[w].TotalPages
                        }
                        q = Math.min(q, s.pager_total_pages);
                        j(w + 1, u)
                    };
                    if (typeof s.cache[v] == "undefined") {
                        s.pager(v + 1, t)
                    } else {
                        t(v + 1, s.cache[v])
                    }
                };
                j(m, n)
            } else {
                if (!this.generator_finished && this.cache.length < l) {
                    var k = function (t) {
                        if (t && t.length == 0) {
                            s.generator_finished = true
                        }
                        s.cache.push.apply(s.cache, t);
                        if (!s.generator_finished && s.cache.length < l) {
                            s.generator(k)
                        } else {
                            n = s.cache.slice(i, l);
                            p()
                        }
                    };
                    this.generator(k)
                } else {
                    n = s.cache.slice(i, l);
                    p()
                }
            }
        }
    })(a);
    var d = ["exports"];
    (function (g, h) {
        g.filterChain = function () {
            this.index = -1;
            this.chain = (arguments.length > 0 ? arguments : [])
        };
        g.filterChain.prototype.register = function (i) {
            this.chain.push(i)
        };
        g.filterChain.prototype.run = function () {
            this.index++;
            if (this.index < this.chain.length) {
                this.chain[this.index].run(this)
            }
        };
        g.i18n = {
            locale: "en",
            messages: {
                zh: {
                    see_detail: "\u8be6\u60c5",
                    no_results: "\u62b1\u6b49\uff01\u6ca1\u6709\u627e\u5230\u76f8\u5173\u7684\u5546\u54c1",
                    hide: "\u9690\u85cf",
                    show: "\u663e\u793a",
                    feedback: "\u53cd\u9988",
                    shoppingassist: "\u5982\u610f\u6dd8",
                    settings: "\u9009\u9879",
                    feedback_url: "http://ruyi.etao.com/feedback",
                    choose_at_least_one: "\u8bf7\u81f3\u5c11\u9009\u4e2d\u4e00\u4e2a\u641c\u7d22\u7f51\u7ad9",
                    homepage: "\u5b98\u65b9\u7f51\u7ad9",
                    search: "\u641c\u7d22",
                    search_engine_setting: "\u641c\u7d22\u5546\u57ce\u8bbe\u7f6e",
                    search_engine_setting_title: "\u641c\u7d22\u5546\u57ce",
                    search_engine_setting_commit: "\u5b8c\u6210",
                    no_products: "\u62b1\u6b49\uff01\u6ca1\u6709\u627e\u5230\u76f8\u5173\u7684\u5546\u54c1",
                    search_engine_setting_msg: "\u8bf7\u81f3\u5c11\u9009\u62e9\u4e00\u4e2a\u5546\u57ce\u3002",
                    search_product_in: '\u5728${1}\u641c\u7d22"${2}"',
                    click_to_hide: "\u70b9\u51fb\u9690\u85cf\u641c\u7d22\u7ed3\u679c"
                },
                en: {
                    see_detail: "See Detail",
                    no_results: "sorry, no results",
                    hide: "Hide",
                    show: "Show",
                    feedback: "Feedback",
                    settings: "Options",
                    shoppingassist: "Shopping Assistant",
                    homepage: "Homepage",
                    choose_at_least_one: "Please select at least one search site",
                    feedback_url: "http://spreadsheets.google.com/viewform?hl=en&formkey=dFhZVkE5ZC1veFk4YzRfVnpDRGtkTWc6MQ",
                    expand: "Expand",
                    collapse: "Collapse",
                    close: "Close",
                    search: "Search",
                    search_engine_setting: "Customize",
                    search_engine_setting_title: "Search On",
                    search_engine_setting_commit: "OK",
                    no_products: "Oops, no results",
                    search_engine_setting_msg: "Please select at least one site.",
                    search_product_in: 'Search "${2}" at ${1}',
                    click_to_hide: "Click to hide"
                },
                fr: {
                    see_detail: "Voir le d\u00e9tail",
                    no_results: "D\u00e9sol\u00e9, aucun r\u00e9sultat",
                    hide: "Hide",
                    show: "Show",
                    feedback: "Feedback",
                    settings: "Options",
                    shoppingassist: "Shopping Assistant",
                    homepage: "Homepage",
                    choose_at_least_one: "Merci de s\u00e9lectionner au moins un site de recherche",
                    feedback_url: "http://spreadsheets.google.com/viewform?hl=en&formkey=dFhZVkE5ZC1veFk4YzRfVnpDRGtkTWc6MQ",
                    expand: "Expand",
                    collapse: "Collapse",
                    close: "Close",
                    search: "Search",
                    search_engine_setting: "Customize",
                    search_engine_setting_title: "Search On",
                    search_engine_setting_commit: "OK",
                    no_products: "Oops, no results",
                    search_engine_setting_msg: "Please select at least one site.",
                    search_product_in: 'Search "${2}" at ${1}',
                    click_to_hide: "Click to hide"
                },
                it: {
                    see_detail: "Vedi dettagli",
                    no_results: "Spiacenti, nessun risultato",
                    hide: "Hide",
                    show: "Show",
                    feedback: "Feedback",
                    settings: "Opzioni",
                    shoppingassist: "Shopping Assistant",
                    homepage: "Homepage",
                    choose_at_least_one: "Prego, selezionare almeno un sito di ricerca",
                    feedback_url: "http://spreadsheets.google.com/viewform?hl=en&formkey=dFhZVkE5ZC1veFk4YzRfVnpDRGtkTWc6MQ",
                    expand: "Expand",
                    collapse: "Collapse",
                    close: "Close",
                    search: "Search",
                    search_engine_setting: "Customize",
                    search_engine_setting_title: "Search On",
                    search_engine_setting_commit: "OK",
                    no_products: "Oops, no results",
                    search_engine_setting_msg: "Please select at least one site.",
                    search_product_in: 'Search "${2}" at ${1}',
                    click_to_hide: "Click to hide"
                },
                de: {
                    see_detail: "Details anschauen",
                    no_results: "Entschuldigung, keine Suchergebnisse",
                    hide: "Verstecken",
                    show: "Zeigen",
                    feedback: "Reaktion",
                    settings: "Optionen",
                    shoppingassist: "Shopping Assistant",
                    homepage: "Startseite",
                    choose_at_least_one: "Bitte w\u00e4hlen Sie mindestens eine Seite zum Durchsuchen aus",
                    feedback_url: "http://spreadsheets.google.com/viewform?hl=en&formkey=dFhZVkE5ZC1veFk4YzRfVnpDRGtkTWc6MQ",
                    expand: "Erweitern",
                    collapse: "Zusammenbruch",
                    close: "in der N\u00e4he",
                    search: "Search",
                    search_engine_setting: "Customize",
                    search_engine_setting_title: "Search On",
                    search_engine_setting_commit: "OK",
                    no_products: "Oops, no results",
                    search_engine_setting_msg: "Please select at least one site.",
                    search_product_in: 'Search "${2}" at ${1}',
                    click_to_hide: "Click to hide"
                }
            },
            setLocale: function (i) {
                if (!(i in this.messages)) {
                    return
                }
                this.locale = i
            },
            getLocale: function () {
                return this.locale
            },
            getMessage: function () {
                var i = arguments;
                var j = i[0];
                var k = "";
                if ((j in this.messages[this.locale])) {
                    k = this.messages[this.locale][j];
                    if (i.length > 1) {
                        k = k.replace(/\$\{\d\}/g, function (m) {
                            var l = m.substring(2, 3);
                            return i[l]
                        })
                    }
                }
                return k
            }
        };
        g.extend = function (o, j, m, q) {
            if (!o || !j) {
                return o
            }
            if (m === h) {
                m = true
            }
            var n, r, k;
            if (q && (k = q.length)) {
                for (n = 0; n < k; n++) {
                    r = q[n];
                    if ((r in j) && (m || !(r in o))) {
                        o[r] = j[r]
                    }
                }
            } else {
                for (r in j) {
                    if (m || !(r in o)) {
                        o[r] = j[r]
                    }
                }
            }
            return o
        };
        g.debounce = function (k, l, i) {
            var m;
            return function j() {
                var p = this;
                var o = arguments;

                function n() {
                    if (!i) {
                        k.apply(p, o)
                    }
                    m = null
                }
                if (m) {
                    clearTimeout(m)
                } else {
                    if (i) {
                        k.apply(p, o)
                    }
                }
                m = setTimeout(n, l || 100)
            }
        };
        g.str_repeat = function (k, j) {
            for (var l = []; j > 0; l[--j] = k) { }
            return l.join("")
        };
        g.sprintf = function () {
            var n = 0,
                t, q = arguments[n++],
                k = [],
                l, j, r, u, v = "";
            while (q) {
                if (l = /^[^\x25]+/.exec(q)) {
                    k.push(l[0])
                } else {
                    if (l = /^\x25{2}/.exec(q)) {
                        k.push("%")
                    } else {
                        if (l = /^\x25(?:(\d+)\$)?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(q)) {
                            if (((t = arguments[l[1] || n++]) == null) || (t == h)) {
                                throw ("Too few arguments.")
                            }
                            if (/[^s]/.test(l[7]) && (typeof (t) != "number")) {
                                throw ("Expecting number but found " + typeof (t))
                            }
                            switch (l[7]) {
                                case "b":
                                    t = t.toString(2);
                                    break;
                                case "c":
                                    t = String.fromCharCode(t);
                                    break;
                                case "d":
                                    t = parseInt(t);
                                    break;
                                case "e":
                                    t = l[6] ? t.toExponential(l[6]) : t.toExponential();
                                    break;
                                case "f":
                                    t = l[6] ? parseFloat(t).toFixed(l[6]) : parseFloat(t);
                                    break;
                                case "o":
                                    t = t.toString(8);
                                    break;
                                case "s":
                                    t = ((t = String(t)) && l[6] ? t.substring(0, l[6]) : t);
                                    break;
                                case "u":
                                    t = Math.abs(t);
                                    break;
                                case "x":
                                    t = t.toString(16);
                                    break;
                                case "X":
                                    t = t.toString(16).toUpperCase();
                                    break
                            }
                            t = (/[def]/.test(l[7]) && l[2] && t >= 0 ? "+" + t : t);
                            r = l[3] ? l[3] == "0" ? "0" : l[3].charAt(1) : " ";
                            u = l[5] - String(t).length - v.length;
                            j = l[5] ? g.str_repeat(r, u) : "";
                            k.push(v + (l[4] ? t + j : j + t))
                        } else {
                            throw ("Huh ?!")
                        }
                    }
                }
                q = q.substring(l[0].length)
            }
            return k.join("")
        };
        g.format_price = function (j, i) {
            if (j <= 0) {
                return ""
            }
            var k = "";
            var l = g.sprintf("%.2f", j / 100);
            switch (i) {
                case "us":
                    k = "$" + l;
                    break;
                case "ca":
                    k = "CDN$" + l;
                    break;
                case "fr":
                case "de":
                    k = "EUR " + l;
                    break;
                case "uk":
                    k = "&#xA3;" + l;
                    break;
                default:
                    k = "$" + l
            }
            return k
        }
    })(a);
    (function (g, h) {
        g.site = {
            SearchTerm: (function () {
                var i = function (k, j) {
                    this.value = k;
                    this.encoding = (typeof j == "undefined" ? (document.charset || document.characterSet || "").toLowerCase() : j)
                };
                i.prototype = {
                    toString: function () {
                        return this.value
                    },
                    getUnicode: function (k) {
                        if (this.value.match(/%u[0-9a-fA-F]{4}/)) {
                            var j = this.value.replace(/%u([0-9a-fA-F]{4})/g, function (m, l) {
                                return String.fromCharCode(parseInt(l, 16))
                            });
                            k(j)
                        } else {
                            if (this.encoding.match(/(x-)?(cp936|gbk|gb2312|gb18030)/)) {
                                g.browser.extension.sendRequest({
                                    topic: "decode_gbk",
                                    data: this.value
                                }, k)
                            } else {
                                k(this.value)
                            }
                        }
                    }
                };
                return i
            })(),
            get_domain: function (i) {
                if (i.location && i.location.hostname) {
                    return i.location.hostname
                }
                return ""
            },
            get_domain_from_str: function (j) {
                var i = "undefined";
                if (j.toLowerCase().indexOf("http://") == 0) {
                    i = j.substring(7);
                    i = "http://" + i.substring(0, i.indexOf("/"))
                } else {
                    if (j.toLowerCase().indexOf("https://") == 0) {
                        i = j.substring(8);
                        i = "https://" + i.substring(0, i.indexOf("/"))
                    }
                }
                return i
            },
            get_url: function (i) {
                if (i.location && i.location.href) {
                    return i.location.href
                }
                if (i.title) {
                    return i.title
                }
                return ""
            },
            get_site: function (k) {
                var j = "";
                if (k) {
                    var i = 2;
                    var l = k.split(".");
                    if (k.match(/\.(com|co|org|net)\.(cn|uk|jp|hk|us|ca)$/)) {
                        i += 1
                    }
                    if (l.length >= i) {
                        j = l.splice(l.length - i, l.length).join(".")
                    } else {
                        j = k
                    }
                }
                return j
            },
            get_sub_domain: function (k, j) {
                var i = "";
                if (k) {
                    if (k.length > j.length) {
                        i = k.substring(0, k.length - j.length - 1)
                    } else {
                        i = "DUMMY"
                    }
                }
                return i
            },
            check_shopping_term: function () {
                var l = this.get_site(this.get_domain(document));
                if (l == "google.com" || l == "google.cn" || l == "google.com.hk" || l == "google.co.uk") {
                    var k = decodeURIComponent(document.location.href);
                    if (k.indexOf("/products") != -1) {
                        return true
                    } else {
                        if (k.indexOf("tbs=bks:1") != -1 || k.indexOf("tbs=shop:1") != -1 || k.indexOf("tbm=bks") != -1 || k.indexOf("tbm=shop") != -1) {
                            return true
                        }
                    }
                } else {
                    if (l == "bing.com") {
                        if (document.location.href.indexOf("/shopping/") != -1) {
                            return true
                        }
                        var j = $("#sw_abarl").find("a");
                        var i = false;
                        $.each(j, function (m, n) {
                            if ($(n).attr("href").indexOf("/shopping/") != -1) {
                                i = true;
                                return
                            }
                        });
                        return i
                    } else {
                        return true
                    }
                }
            },
            get_search_term: function (m, n) {
                if (!this.check_shopping_term()) {
                    return false
                }
                var l = "";
                var k = this.get_domain(n);
                var j = this.get_site(k);
                var i = this.get_sub_domain(k, j);
                if (m[i]) {
                    if (typeof m[i].e == "undefined") {
                        l = this.extract_search_term(m[i], n)
                    }
                }
                if (l && typeof l == "string") {
                    l = new this.SearchTerm(l)
                }
                return l
            },
            extract_search_term: function (m, r) {
                var o = "";
                var j = r.location.href;
                for (var n = 0; n < m.length; n++) {
                    var q = m[n].k;
                    var p = m[n].d;
                    var l = m[n].s;
                    var k = m[n].sk;
                    if (q) {
                        o = this.find_search_term_from_query(j, q, p)
                    }
                    if (o.length == 0 && l) {
                        o = this.find_search_term_from_document(r, l);
                        if (k && k == o) {
                            o = ""
                        }
                    }
                    if (o) {
                        break
                    }
                }
                return o
            },
            find_search_term_from_query: function (l, j, q) {
                var o = "";
                var p = l.split(q);
                var n = new RegExp("(?:^|\\?)" + j + '=([^#;/\\?:@=&{}\\|\\\\^~\\[\\]`<>\\"]*)');
                for (var m = 0; m < p.length; m++) {
                    var k = n.exec(p[m]);
                    if (k) {
                        o = k[1]
                    }
                }
                if (o) {
                    o = o.replace(/\+/g, " ")
                }
                return o
            },
            find_search_term_from_document: function (n, j) {
                var m = "";
                var k = n.getElementsByTagName("input");
                for (var l = 0; l < k.length; l++) {
                    if (k[l].id == j || k[l].name == j) {
                        m = k[l].value;
                        break
                    }
                }
                return m ? new this.SearchTerm(m, "unicode") : m
            }
        }
    })(a);
    (function (g) {
        if (!g.SearchBox) {
            g.SearchBox = {}
        }
        g.SearchBox.Tmpl = {
            getSearchEngineSettingTemplate: function (r) {
                var j = r.length;
                var s = '<tr class="ruyitao-ses-row">';
                var l = '<td class="ruyitao-ses-cell">';
                var o = [];
                var p;
                var q;
                var n;
                var m;
                var h;
                for (var k = 0; k < j; k++) {
                    if (k % 2 == 0) {
                        o.push(s)
                    }
                    m = r[k];
                    h = m.name;
                    q = m.enabled ? 'checked="checked"' : "";
                    p = '<input type="checkbox" id="ruyitao-ses-' + h + '" value="' + h + '" class="ruyitao-ses" ' + q + "/>";
                    n = '<label class="ruyitao-ses-label" for="ruyitao-ses-' + h + '">' + m.title + "</label>";
                    o.push(l + p + n + "</td>");
                    if (k % 2 == 1 || j == k + 1) {
                        o.push("</tr>")
                    }
                }
                return o.join("")
            },
            getSearchEnginesTemplate: function (h) {
                var j = h.length;
                var k = [];
                var n;
                for (var m = 0; m < j; m++) {
                    n = h[m];
                    k.push('<li id="ruyitao-se-' + n.name + '" data-se-id="' + n.name + '" class="ruyitao-se" data-se-name="' + n.title + '">');
                    k.push('<img src="' + n.icon + '" /></li>')
                }
                return k.join("")
            },
            getProductsTemplate: function (o) {
                var j = o.length;
                var s;
                var n = g.SearchBox.Util.getURL("assets/images/loading.gif");
                var q = '<span class="ruyitao-product-image-wrapper"><img class="ruyitao-product-image" src="' + n + '" /><b class="ruyitao-line-height-setter"></b></span>';
                var h;
                var p = [];
                var r;
                var m;
                for (var k = 0; k < j; k++) {
                    r = o[k];
                    s = '<li class="ruyitao-product-item" data-click-url="' + r.detailUrl + '" title="' + r.Title + '">';
                    m = r.preferredPrice;
                    if (m.substring(0, 4) != "<img") {
                        m = '<span class="ruyitao-product-price-wrapper">' + m + "</span>"
                    }
                    h = '<div class="ruyitao-product-price">' + m + "</div>";
                    p.push(s + q + h + "</li>")
                }
                return p.join("")
            },
            getProductDetailTemplate: function (i) {
                var h = [];
                h.push('<div id="ruyitao-product-title">');
                h.push('<span id="ruyitao-product-page-link" title="' + i.Title + '" data-href="' + i.productDetailUrl + '">' + i.Title + "</span>");
                h.push('</div><div id="ruyitao-product-price">');
                h.push('<span id="ruyitao-product-used-price">' + i.productUsedPrice + "</span>");
                h.push('<span id="ruyitao-product-now-price">' + i.productPrice + "</span>");
                h.push('</div><div id="ruyitao-product-image">');
                h.push('<img data-href="' + i.productDetailUrl + '" src="' + i.productImageUrl + '" />');
                h.push('<span class="ruyitao-line-height-setter"></span></div>');
                h.push('<div id="ruyitao-product-fast-trick">' + i.productFastTrack + "</div>");
                h.push('<div id="ruyitao-product-rating-stars">' + i.productRatingStars + "</div>");
                return h.join("")
            },
            getMarketsTemplate: function (k) {
                var j = [];
                var h = k.length;
                var n;
                for (var m = 0; m < h; m++) {
                    n = k[m];
                    j.push('<li class="ruyitao-market-item" data-href="' + n.DetailUrl + '" title="' + n.Title + '">');
                    j.push('<div class="ruyitao-market-name">' + n.ShopName + "</div>");
                    j.push('<div class="ruyitao-price">' + n.Price + "</div></li>")
                }
                return j.join("")
            }
        }
    })(a);
    (function (h, i, j) {
        if (!h.SearchBox) {
            h.SearchBox = {}
        }
        var g = {};
        h.SearchBox.Util = {
            getURL: function (k) {
                return h.browser.extension.getURL(k)
            },
            openTab: function (l, k) {
                k = k || false;
                h.browser.extension.sendRequest({
                    topic: "tab_open",
                    url: l,
                    selected: k
                })
            },
            ga: function (k) {
                k.topic = "ga_push";
                h.browser.extension.sendRequest(k)
            },
            sendLog: function (m, l) {
                var k = {
                    topic: "send_log",
                    action: m
                };
                if (typeof l != "undefined") {
                    k.label = l
                }
                h.browser.extension.sendRequest(k)
            },
            getViewPortWidth: function () {
                return document.documentElement.clientWidth
            },
            handleSogou: function () {
                var k = i.navigator.userAgent;
                if (/SE\s\d\.X\sMetaSr\s\d\.\d/g.test(k)) {
                    $("#ruyitao-option-link").hide()
                }
            }
        }
    })(a, window);
    (function (g, h, i) {
        if (!g.SearchBox) {
            g.SearchBox = {}
        }
        var j = g.SearchBox;
        j.UI = {
            visibleProductNum: null,
            init: function () { },
            activateControlIcon: function (k) {
                $(k).addClass("ruyitao-active-control-icon");
                if ($(k).hasClass("ruyitao-se")) {
                    this.updateSearchEngineTitle(k, true)
                }
            },
            inactivateControlIcon: function (k) {
                $(k).removeClass("ruyitao-active-control-icon");
                if ($(k).hasClass("ruyitao-se")) {
                    this.updateSearchEngineTitle(k, false)
                }
            },
            isActiveControlIcon: function (k) {
                return $(k).hasClass("ruyitao-active-control-icon")
            },
            updateSearchEngineTitle: function (k, n) {
                var l = $(k);
                var p = l.attr("data-se-name");
                var m = j.App.getKeyword();
                var o = g.i18n.getMessage("search_product_in", p, m);
                if (n) {
                    o = g.i18n.getMessage("click_to_hide")
                }
                l.attr("title", o)
            },
            showOptionList: function () {
                $("#ruyitao-option-list-content").show()
            },
            hideOptionList: function () {
                $("#ruyitao-option-list-content").hide()
            },
            showSearchBar: function () {
                $("#ruyitao-search-bar").show();
                this.activateControlIcon($("#ruyitao-search-icon"))
            },
            hideSearchBar: function () {
                $("#ruyitao-search-bar").hide();
                this.inactivateControlIcon($("#ruyitao-search-icon"))
            },
            focusSearch: function () {
                $("#ruyitao-search").get(0).focus()
            },
            showSearchEngineSetting: function () {
                $("#ruyitao-search-engines-setting").show();
                this.activateControlIcon($("#ruyitao-plus-btn"))
            },
            hideSearchEngineSetting: function () {
                $("#ruyitao-search-engines-setting").hide();
                this.inactivateControlIcon($("#ruyitao-plus-btn"))
            },
            showSearchEngineSettingMsg: function () {
                $("#ruyitao-ses-msg").show()
            },
            hideSearchEngineSettingMsg: function () {
                $("#ruyitao-ses-msg").hide()
            },
            hideOtherPopups: function (k) {
                $(".ruyitao-popup").filter('[id!="' + k + '"]').hide()
            },
            hidePopups: function () {
                this.hideOptionList();
                this.hideSearchBar();
                this.hideSearchEngineSetting()
            },
            showControlBar: function () {
                if ($.browser.msie && parseInt($.browser.version) < 9) {
                    $("#ruyitao-controller-bar").css("filter", "")
                } else {
                    $("#ruyitao-controller-bar").css("opacity", 1)
                }
            },
            transparentizeControlBar: function () {
                $("#ruyitao-controller-bar").css("opacity", 0.3)
            },
            showTeaching: function () {
                $("#ruyitao-teaching").show()
            },
            hideTeaching: function () {
                $("#ruyitao-teaching").hide()
            },
            showOverlay: function () {
                var m = $("#ruyitao-overlay");
                m.show();
                var l = document.body;
                var n = document.documentElement;
                var o = Math.max(n.clientWidth, l.scrollWidth);
                var k = Math.max(n.clientHeight, l.scrollHeight);
                m.width(o).height(k)
            },
            hideOverlay: function () {
                $("#ruyitao-overlay").hide()
            },
            enableSearchEngineHover: function () {
                $("#ruyitao-search-engines").addClass("ruyitao-se-hover-enabled")
            },
            disableSearchEngineHover: function () {
                $("#ruyitao-search-engines").removeClass("ruyitao-se-hover-enabled")
            }
        }
    })(a, window);
    (function (l, p) {
        if (!l.SearchBox) {
            l.SearchBox = {}
        }
        var h = l.SearchBox;
        var o = l.SearchBox.Util;
        var j = l.SearchBox.UI;
        var i = h.Tmpl;
        var g;
        var k;
        var n;
        var m = false;
        l.SearchBox.SearchEngines = {
            init: function () {
                this.renderEnabledSearchEngines();
                this.registerEvents()
            },
            registerEvents: function () {
                var q = this;
                $("#ruyitao-submit-ses-btn").click(function (r) {
                    r.preventDefault();
                    q.submit()
                })
            },
            getAll: function (q) {
                var r = this;
                l.browser.extension.sendRequest({
                    topic: "get_search_engines"
                }, function (s) {
                    g = s.search_engines;
                    r.setEnabled(g);
                    r.setLocale(s.locale);
                    q(s)
                })
            },
            updateCached: function (v) {
                var s;
                var w;
                var r;
                for (var q in g) {
                    if (g.hasOwnProperty(q)) {
                        s = g[q];
                        for (var u = 0, t = s.length; u < t; u++) {
                            w = s[u];
                            r = w.name;
                            if (v.hasOwnProperty(r)) {
                                w.enabled = v[r]
                            }
                        }
                    }
                }
            },
            setLocale: function (q) {
                n = q;
                l.i18n.setLocale(q)
            },
            getLocale: function () {
                return n
            },
            getCachedAll: function () {
                return g
            },
            filter: function (r) {
                m = true;
                var v = l.site.get_site(p.location.hostname);
                var q = [];
                for (var t = 0, s = r.length; t < s; t++) {
                    var u = r[t];
                    if (u.name == "etao" || u.name == "ebay" || ((v == "paipai.com" || v == "eachnet.com") && u.name == "taobao")) { } else {
                        q.push(u)
                    }
                }
                return q
            },
            sort: function (q) {
                q.sort(function (r, s) {
                    return r.order - s.order
                })
            },
            renderSearchEngineSettingHtml: function () {
                var s = this.getCachedAll();
                var u = this.getLocale();
                var r = [];
                for (var q in s) {
                    if (s.hasOwnProperty(q) && q == u) {
                        r = Array.prototype.concat.apply(r, s[q])
                    }
                }
                r = this.filter(r);
                var t = i.getSearchEngineSettingTemplate(r);
                $("#ruyitao-ses-tbody").html(t)
            },
            renderEnabledSearchEngines: function () {
                var q = this.getEnabled();
                this.sort(q);
                var s = $("#ruyitao-search-engine-item-template").html();
                $.each(q, function (t, u) {
                    u.icon = u.icon || o.getURL("assets/images/search/se-icons/" + u.name + ".png")
                });
                var r = i.getSearchEnginesTemplate(q);
                $("#ruyitao-search-engines").html(r)
            },
            setSearchEngineSettingPosition: function () {
                var q = $("#ruyitao-plus-btn");
                var s = $("#ruyitao-search-engines-setting");
                var r = q.position().left + q.width() / 2;
                var u = s.outerWidth();
                var t = r - u / 2;
                if (t < 0) {
                    t = 0
                }
                s.css("left", t + "px")
            },
            setTitles: function () {
                $("#ruyitao-search-engines .ruyitao-se").each(function () {
                    var s = $(this).attr("data-se-name");
                    var q = h.App.getKeyword();
                    var r = l.i18n.getMessage("search_product_in", s, q);
                    $(this).attr("title", r)
                })
            },
            getEnabled: function () {
                return k
            },
            setEnabled: function (r) {
                r = r || this.getCachedAll();
                var u = l.site.get_site(p.location.hostname);
                var s = [];
                var t = function (w) {
                    var y = r[w];
                    var x, v;
                    for (x = 0, v = y.length; x < v; x++) {
                        var z = y[x];
                        if (z.enabled && !(z.host && u.match(z.host))) {
                            if ((u == "paipai.com" || u == "eachnet.com") && (z.name == "taobao" || z.name == "etao")) { } else {
                                s.push(z)
                            }
                        }
                    }
                };
                if (r[n]) {
                    t(n)
                }
                for (var q in r) {
                    if (r.hasOwnProperty(q) && q != n) {
                        t(q)
                    }
                }
                k = s
            },
            submit: function () {
                var r = {};
                var v = 0;
                var q;
                var t;
                $("#ruyitao-ses-table .ruyitao-ses").each(function () {
                    q = $(this).val();
                    t = this.checked;
                    r[q] = t;
                    t && v++
                });
                if (m || v) {
                    l.browser.extension.sendRequest({
                        topic: "set_search_engine",
                        search_engines: r
                    });
                    this.updateCached(r);
                    this.setEnabled();
                    this.renderEnabledSearchEngines();
                    if (h.App.getKeyword()) {
                        this.setTitles()
                    }
                    j.hideSearchEngineSettingMsg();
                    $("#ruyitao-plus-btn").trigger("click");
                    var s = h.App;
                    var u = s.getCurrentSearchEngine();
                    if (!s.checkCurrentSearchEngineIsEnabled()) {
                        u = this.getEnabled()[0].name
                    }
                    s.selectSearchEngine(u)
                } else {
                    j.showSearchEngineSettingMsg()
                }
            }
        }
    })(a, document);
    (function (l, k) {
        if (!l.SearchBox) {
            l.SearchBox = {}
        }
        var r = l.SearchBox;
        var m = r.Util;
        var p = r.UI;
        var v = r.Tmpl;
        var t = 10;
        var h = r.Products = {
            keyword: "",
            searchEngine: "",
            productNumPerPage: 0,
            pageCache: null,
            maxPageNum: f,
            loading: false,
            arrowManualDisabled: false,
            prevArrowValid: true,
            nextArrowValid: true,
            arrowValidDelay: 200,
            init: function () {
                var y = w.calcProductNumByViewPortWidth();
                this.setProductNumPerPage(y);
                this.reset();
                this.registerEvents()
            },
            registerEvents: function () {
                var y = this;
                var z = $("#ruyitao-product-list");
                z.delegate(".ruyitao-product-item", "click", function () {
                    var A = $(this).attr("data-click-url");
                    m.openTab(A);
                    m.sendLog("click", A);
                    m.ga({
                        category: "[" + l.i18n.getLocale() + "]SearchBox:Mouse",
                        action: "MainBox",
                        label: l.site.get_domain_from_str(A)
                    })
                });
                z.delegate(".ruyitao-product-item", "mouseenter", function () {
                    clearTimeout(n.timer);
                    var A = z.find(".ruyitao-product-item").index(this);
                    var B = y.productsData[A];
                    n.render(B);
                    n.show(this)
                }).delegate(".ruyitao-product-item", "mouseleave", function () {
                    n.timer = setTimeout(function () {
                        n.hide()
                    }, n.delay)
                });
                $("#ruyitao-prev-page-btn").click(function () {
                    if (y.hasPrevPage() && y.prevArrowValid) {
                        y.prevArrowValid = false;
                        var A = y.getProductNumPerPage();
                        w.setProductListWrapperWidthByProductNum(A);
                        w.moveProductList("prev");
                        y.currentPageNum--;
                        y.setArrowStatus();
                        m.ga({
                            category: "[" + l.i18n.getLocale() + "]SearchBox:Mouse",
                            action: "Click_PrevPage",
                            label: $(".ruyitao-active-control-icon").attr("title")
                        });
                        setTimeout(function () {
                            y.prevArrowValid = true
                        }, y.arrowValidDelay)
                    }
                });
                $("#ruyitao-next-page-btn").click(function () {
                    if (y.hasNextPage() && y.nextArrowValid) {
                        y.nextArrowValid = false;
                        y.searchNextPage(function () {
                            w.moveProductList("next");
                            y.setArrowStatus();
                            setTimeout(function () {
                                y.nextArrowValid = true
                            }, y.arrowValidDelay)
                        });
                        m.ga({
                            category: "[" + l.i18n.getLocale() + "]SearchBox:Mouse",
                            action: "Click_Nextpage",
                            label: $(".ruyitao-active-control-icon").attr("title")
                        })
                    }
                })
            },
            reset: function () {
                var z = this;
                this.productsData = [];
                this.maxPageNum = 0;
                this.currentPageNum = 0;
                this.loading = false;
                g.cancel("searchbox_next");
                var A = (function () {
                    var C = 1;
                    var B = f;
                    return function (D) {
                        if (typeof B == "undefined" || C <= B) {
                            l.browser.extension.sendRequest({
                                topic: "item_search",
                                Keyword: z.getKeyword(),
                                SearchEngine: z.getSearchEngine(),
                                ItemPage: C
                            }, function (E) {
                                C++;
                                if ("Code" in E) {
                                    l.console.debug(E.Message);
                                    D([])
                                } else {
                                    B = E.TotalPages;
                                    if (B) {
                                        return D(E.Items)
                                    } else {
                                        return D([])
                                    }
                                }
                            })
                        } else {
                            D([])
                        }
                    }
                })();
                var y = this.getProductNumPerPage();
                this.pageCache = l.PageCache(A, {
                    PageSize: y
                }, true)
            },
            searchNextPage: function (z) {
                var y = $("#ruyitao-product-list .ruyitao-product-item").length;
                var A = this.getProductNumPerPage();
                var C = A * this.currentPageNum;
                if (C < y) {
                    this.currentPageNum++;
                    var D = Math.min(y - C, A);
                    w.setProductListWrapperWidthByProductNum(D);
                    z()
                } else {
                    var B = this.getSearchEngine();
                    var E = this.getKeyword();
                    this.search(B, E, this.currentPageNum + 1, null, z)
                }
            },
            doNewSearch: function (y, z) {
                this.reset();
                this.search(y, z, 1, function () {
                    w.clear();
                    w.reset()
                })
            },
            search: function (B, A, C, E, z) {
                var y = this;
                this.setSearchEngine(B);
                this.setKeyword(A);
                w.hideNoResult();
                this.manualDisableAllArrow();
                w.showLoading();
                var D = g.register("searchbox_next", function (F) {
                    y.maxPageNum = F.TotalPages || t;
                    E && E();
                    y.searchSuccess(F.Entries, z)
                });
                this.pageCache.get(C, D)
            },
            searchSuccess: function (B, z) {
                var y = this;
                w.hideLoading();
                this.manualEnableAllArrow();
                var A = B.length;
                if (A) {
                    B = this.filter(B);
                    this.productsData = this.productsData.concat(B);
                    w.render(B);
                    w.setProductListWrapperWidthByProductNum(A);
                    z && z();
                    this.currentPageNum++
                } else {
                    this.maxPageNum = this.currentPageNum;
                    setTimeout(function () {
                        y.nextArrowValid = true
                    }, y.arrowValidDelay);
                    if (this.currentPageNum == 0) {
                        w.showNoResult()
                    }
                }
                this.setArrowStatus()
            },
            filter: function (y) {
                $.each(y, function (A, B) {
                    B.SmallImageUrl = B.SmallImageUrl || l.browser.extension.getURL("assets/images/no_image_available.png");
                    var z = B.Price || "";
                    if (z.match(/too low/i)) {
                        z = "Too low"
                    } else {
                        if (z.indexOf("-") != -1) {
                            z = $.trim(z.split("-")[0]) || "&nbsp;"
                        } else {
                            z = $.trim(z) || "&nbsp;"
                        }
                    }
                    B.preferredPrice = z
                });
                return y
            },
            setArrowStatus: function () {
                w.disableAllArrow();
                if (this.hasPrevPage()) {
                    w.enableArrowBtn("prev")
                }
                if (this.hasNextPage()) {
                    w.enableArrowBtn("next")
                }
            },
            hasPrevPage: function () {
                return !this.arrowManualDisabled && this.currentPageNum > 1
            },
            hasNextPage: function () {
                return !this.arrowManualDisabled && this.currentPageNum < this.maxPageNum
            },
            manualDisableAllArrow: function () {
                this.arrowManualDisabled = true;
                w.disableAllArrow()
            },
            manualEnableAllArrow: function () {
                this.arrowManualDisabled = false
            },
            getKeyword: function () {
                return this.keyword
            },
            setKeyword: function (y) {
                try {
                    this.keyword = decodeURIComponent(y)
                } catch (z) {
                    this.keyword = ""
                }
            },
            getSearchEngine: function () {
                return this.searchEngine
            },
            setSearchEngine: function (y) {
                this.searchEngine = y
            },
            getProductNumPerPage: function () {
                return this.productNumPerPage
            },
            setProductNumPerPage: function (y) {
                this.productNumPerPage = y
            }
        };
        var o = 20;
        var j = 20;
        var s = 30;
        var x = 80;
        var q = 3;
        var i = 20;
        var u = 50;
        var w = r.ProductsView = {
            viewPortWidth: 0,
            resizeTimer: null,
            resizeDelay: 100,
            init: function () {
                this.viewPortWidth = m.getViewPortWidth();
                this.registerEvents();
                n.init()
            },
            reset: function () {
                $("#ruyitao-product-list").hide().css("left", 0).show();
                this.disableAllArrow()
            },
            registerEvents: function () {
                var y = this;
                $(window).resize(function () {
                    clearTimeout(y.resizeTimer);
                    y.resizeTimer = setTimeout(function () {
                        if (m.getViewPortWidth() != y.viewPortWidth) {
                            y.viewPortWidth = m.getViewPortWidth();
                            var B = y.calcProductNumByViewPortWidth();
                            h.setProductNumPerPage(B);
                            var z = h.getSearchEngine();
                            var A = h.getKeyword();
                            h.doNewSearch(z, A)
                        }
                    }, y.resizeDelay)
                })
            },
            calcProductNumByViewPortWidth: function () {
                var z = m.getViewPortWidth();
                var y = z - o - j - s * 2;
                var A = Math.floor(y / x);
                if (A < q) {
                    A = q
                } else {
                    if (A > i) {
                        A = i
                    }
                }
                return A
            },
            setProductListWrapperWidthByProductNum: function (y) {
                var z = y * x;
                $("#ruyitao-product-list-wrapper").width(z)
            },
            show: function () {
                $("#ruyitao-products-wrapper").show()
            },
            hide: function () {
                $("#ruyitao-products-wrapper").hide()
            },
            render: function (C) {
                var I = $("#ruyitao-product-item-template").html();
                var H = /\.(taobao|tmall)\.com/;
                var B = k.location.href;
                var F = H.test(B);
                $.each(C, function (K, L) {
                    var J = L.DetailPageURL;
                    if (F && H.test(J)) {
                        L.detailUrl = J
                    } else {
                        L.detailUrl = L.ClickUrl || J
                    }
                });
                var D = v.getProductsTemplate(C);
                var y = $("#ruyitao-product-list");
                y.append(D);
                var z = y.find(".ruyitao-product-image");
                var A = z.length;
                var E = z.length - C.length;
                var G = 0;
                z.each(function (J) {
                    if (J >= E && J < A) {
                        if ($.browser.msie && $.browser.version == "6.0") {
                            l.IE6Patch.fixImageMaxSize($(this), u)
                        }
                        $(this).attr("src", C[G++].SmallImageUrl)
                    }
                })
            },
            clear: function () {
                $("#ruyitao-product-list").html("")
            },
            showLoading: function () {
                $("#ruyitao-product-list-overlay").show()
            },
            hideLoading: function () {
                $("#ruyitao-product-list-overlay").hide()
            },
            showNoResult: function () {
                $("#ruyitao-message").show()
            },
            hideNoResult: function () {
                $("#ruyitao-message").hide()
            },
            enableArrowBtn: function (y) {
                $("#ruyitao-" + y + "-page-btn").addClass("ruyitao-active-arrow")
            },
            disableArrowBtn: function (y) {
                $("#ruyitao-" + y + "-page-btn").removeClass("ruyitao-active-arrow")
            },
            disableAllArrow: function () {
                this.disableArrowBtn("prev");
                this.disableArrowBtn("next")
            },
            setProductListWrapperWidth: function (y) {
                $("#ruyitao-product-list-wrapper").width(y)
            },
            getProductListWrapperWidth: function () {
                $("#ruyitao-product-list-wrapper").width()
            },
            moveProductList: function (z) {
                var y = $("#ruyitao-product-list");
                var A = y.position().left;
                var B = x * h.getProductNumPerPage();
                if (z == "next") {
                    A = A - B
                } else {
                    if (z == "prev") {
                        A = A + B
                    }
                }
                y.css("left", A)
            }
        };
        var n = r.Popup = {
            timer: null,
            delay: 200,
            init: function () {
                var y = this;
                $("#ruyitao-product-detail-container").mouseenter(function () {
                    clearTimeout(y.timer)
                }).mouseleave(function () {
                    y.hide()
                });
                $("#ruyitao-product-detail-container").delegate("#ruyitao-product-page-link, #ruyitao-product-image > img", "click", function () {
                    var z = $(this).attr("data-href");
                    m.openTab(z);
                    m.sendLog("click", z);
                    m.ga({
                        category: "[" + l.i18n.getLocale() + "]SearchBox:Mouse",
                        action: "Popup",
                        label: l.site.get_domain_from_str(z)
                    })
                })
            },
            setPosition: function (A) {
                var y = $("#ruyitao-product-detail-container");
                var B = y.outerWidth();
                var D = $(A).offset().left + x / 2;
                var E = D - B / 2 - o;
                var z = m.getViewPortWidth();
                if (E < 0) {
                    E = -1
                }
                var C = z - B - j - o;
                if (E > C) {
                    E = C
                }
                y.css("left", E + "px")
            },
            show: function (y) {
                $("#ruyitao-product-detail-container").show();
                this.setPosition(y);
                m.ga({
                    category: "[" + l.i18n.getLocale() + "]SearchBox:Mouse",
                    action: "Over_Pic",
                    label: $(".ruyitao-ui-tabs-selected a").text()
                })
            },
            hide: function () {
                $("#ruyitao-product-detail-container").hide()
            },
            filter: function (B) {
                B.productImageUrl = B.LargeImageUrl || B.SmallImageUrl;
                B.productUsedPrice = B.UsedPrice || "";
                B.productPrice = B.Price || "";
                B.productRatingStars = B.Stars || "";
                B.productFastTrack = B.FastTrack || "";
                var A = /\.(taobao|tmall)\.com/;
                var z = k.location.href;
                var C = A.test(z);
                var y = B.DetailPageURL;
                if (C && A.test(y)) {
                    B.productDetailUrl = y
                } else {
                    B.productDetailUrl = B.ClickUrl || y
                }
                return B
            },
            render: function (D) {
                var y = $("#ruyitao-product-detail-container");
                var B;
                var C = 240;
                if (D.Popup) {
                    y.addClass("ruyitao-product-detail-container-for-etao");
                    this.renderForEtao(D.Popup);
                    B = $("#ruyitao-product-image-for-etao img");
                    C = 100
                } else {
                    y.removeClass("ruyitao-product-detail-container-for-etao");
                    D = this.filter(D);
                    var A = $("#ruyitao-product-detail-template").html();
                    var z = v.getProductDetailTemplate(D);
                    $("#ruyitao-product-detail-container").html(z);
                    B = $("#ruyitao-product-image img")
                }
                if ($.browser.msie && $.browser.version == "6.0") {
                    l.IE6Patch.fixImageMaxSize(B, C)
                }
            },
            renderForEtao: function (z) {
                var y = $("#ruyitao-product-detail-container");
                if (z.indexOf("http://") == 0) {
                    y.html('<div class="ruyitao-popup-loading"></div>');
                    l.browser.extension.sendRequest({
                        topic: "ajax",
                        url: z,
                        dataType: "text"
                    }, function (B) {
                        if (typeof B == "string") {
                            A(B)
                        }
                    })
                } else {
                    A(z)
                }
                function A(B) {
                    y.html(B)
                }
            }
        };
        var g = {
            callback_id: 1,
            callbacks: {},
            keys: function (A) {
                var z = [];
                for (var y in A) {
                    z.push(y)
                }
                return z
            },
            register: function (A, B) {
                var y = this;
                this.cancel(A);
                var z = this.callback_id++;
                this.callbacks[A][z] = B;
                return function () {
                    var C = y.get(A, z);
                    if (C) {
                        C.apply(C, arguments);
                        y.cancel(A)
                    }
                }
            },
            cancel: function (y) {
                this.callbacks[y] = {}
            },
            get: function (z, y) {
                if (typeof this.callbacks[z] == "object" && typeof this.callbacks[z][y] == "function") {
                    return this.callbacks[z][y]
                }
            }
        }
    })(a, window);
    (function (n, r, v) {
        if (!n.SearchBox) {
            n.SearchBox = {}
        }
        var i = n.SearchBox;
        var l = i.UI;
        var u = i.Util;
        var o = i.SearchEngines;
        var q = i.Products;
        var k = i.ProductsView;
        var t = "views/searchbox.html";
        var s = null;
        var g = null;
        var j = {};
        var m = null;
        var p;
        var h = 80;
        n.SearchBox.App = {
            searchEngine: "",
            hideControlBarTimer: null,
            hideControlBarDelay: 10000,
            isFirstShown: false,
            isTeachingShown: false,
            run: function (y) {
                var w = this;
                var z = n.site.get_domain(v);
                var x = n.site.get_site(z);
                var A = function (B) {
                    if (!B.config) {
                        y.run();
                        return
                    }
                    j = B;
                    var C = w.getSearchTerm(B);
                    n.console.debug("get search term '" + C + "'");
                    if (C) {
                        if (typeof n.loadJQuery == "function") {
                            $ = jQuery = n.loadJQuery()
                        }
                        w.init(C)
                    } else {
                        y.run()
                    }
                    w.handleAjaxSearch(z)
                };
                o.getAll(function () {
                    if (o.getEnabled().length > 0) {
                        w.getSiteConfig(x, A)
                    }
                })
            },
            getSiteConfig: function (x, w) {
                n.browser.extension.sendRequest({
                    topic: "get_site_config",
                    domain: x
                }, w)
            },
            getSearchTerm: function (w) {
                return n.site.get_search_term(w.config, v)
            },
            getKeyword: function () {
                return p
            },
            setKeyword: function (w) {
                m = p;
                try {
                    p = decodeURIComponent(w)
                } catch (x) {
                    p = ""
                }
                $("#ruyitao-search").val(p)
            },
            handleAjaxSearch: function (y) {
                var x = this;
                if (y == "www.amazon.cn") {
                    var w = $("#twotabsearchtextbox");
                    z(function () {
                        var A = w.val();
                        if (A && A != m) {
                            var B = x.getCurrentSearchEngine();
                            x.setKeyword(A);
                            x.selectSearchEngine(B)
                        }
                    }, w.get().form)
                }
                function z(A, B) {
                    if ("onhashchange" in r) {
                        $(window).bind("hashchange", function () {
                            A()
                        })
                    } else {
                        if (B) {
                            $(B).submit(function () {
                                A()
                            })
                        } else {
                            setInterval(A, 1000)
                        }
                    }
                }
            },
            init: function (x) {
                if ($("#ruyitao-controller-bar").length || $("#ruyitao-products-wrapper").length) {
                    return
                }
                var w = this;
                this.fixFlash();
                this.getTemplate(function (y) {
                    $(document.body).append(y);
                    o.init();
                    w.doI18n();
                    w.registerEvents();
                    var A = o.getEnabled()[0].name;
                    q.init();
                    k.init();
                    u.handleSogou();
                    var z = function (C) {
                        w.setKeyword(C);
                        o.setTitles();
                        if ($.browser.msie && $.browser.version == "6.0") {
                            n.IE6Patch.init();
                            n.IE6Patch.setBarPosition(h);
                            n.IE6Patch.resetPosition()
                        }
                        l.showControlBar();
                        if (document.location.href.indexOf("ruyi.etao.com/demo") != -1) {
                            w.isTeachingShown = true;
                            l.showOverlay();
                            l.showTeaching();
                            w.flashFirstSearchEngine()
                        }
                        w.getSiteStatus(function (E) {
                            if (E) {
                                w.selectSearchEngine(A)
                            } else {
                                q.doNewSearch(A, C);
                                w.transparentizeControlBar()
                            }
                            w.searchEngine = A
                        });
                        if (!j.status) {
                            var D = "Hidden"
                        }
                        var B = n.i18n.getLocale();
                        u.sendLog("show", document.location.href);
                        u.ga({
                            category: "[" + B + "]SearchBox:Status",
                            action: D,
                            label: n.site.get_domain(document)
                        });
                        u.ga({
                            category: "[" + B + "]Searchbox:Misc",
                            action: "BoxWidth",
                            label: k.getProductListWrapperWidth(),
                            value: k.getProductListWrapperWidth()
                        });
                        u.ga({
                            category: "[" + B + "]SearchBox:Search",
                            action: "[HTTP]" + n.site.get_domain(document),
                            label: C
                        })
                    };
                    if (typeof x == "object" && typeof x.getUnicode == "function") {
                        x.getUnicode(z)
                    } else {
                        z(x)
                    }
                })
            },
            flashTimer: null,
            flashDelay: 800,
            flashFirstSearchEngine: function () {
                var w = $("#ruyitao-search-engines .ruyitao-se").eq(0);
                w.addClass("ruyitao-active-control-icon");
                this.flashTimer = setInterval(function () {
                    if (w.hasClass("ruyitao-active-control-icon")) {
                        w.removeClass("ruyitao-active-control-icon")
                    } else {
                        w.addClass("ruyitao-active-control-icon")
                    }
                }, this.flashDelay)
            },
            clearFlashSearchEngine: function () {
                clearInterval(this.flashTimer)
            },
            fixFlash: function () {
                var w = $('embed[type="application/x-shockwave-flash"]');
                var x = null;
                $.each(w, function (z, y) {
                    x = $(y).clone(true);
                    x.attr("wmode", "transparent");
                    $(y).replaceWith(x)
                })
            },
            getTemplate: function (w) {
                n.browser.extension.sendRequest({
                    topic: "get_template",
                    page: t
                }, function (x) {
                    w(x)
                })
            },
            transparentizeControlBar: function () {
                if ($("#ruyitao-products-wrapper").is(":hidden") && !this.isTeachingShown) {
                    this.hideControlBarTimer = setTimeout(function () {
                        l.transparentizeControlBar()
                    }, this.hideControlBarDelay)
                }
            },
            registerEvents: function () {
                var w = this;
                $("#ruyitao-controller-bar").mouseenter(function () {
                    clearTimeout(w.hideControlBarTimer);
                    l.showControlBar()
                }).mouseleave(function () {
                    w.transparentizeControlBar()
                });
                $("#ruyitao-logo").click(function (y) {
                    var x = $(this).attr("data-icon-id");
                    y.stopPropagation();
                    l.hidePopups();
                    if (x == w.getActiveControllerIcon()) {
                        l.hideOptionList();
                        x = null
                    } else {
                        l.showOptionList()
                    }
                    w.setActiveControllerIcon(x)
                });
                $("#ruyitao-search-engines").delegate(".ruyitao-se", "click", function (z) {
                    var y = $(this);
                    var x = y.attr("data-se-id");
                    if (x == w.getCurrentSearchEngine()) {
                        l.inactivateControlIcon(this);
                        k.hide();
                        w.setSiteStatus(false);
                        w.setCurrentSearchEngine(null);
                        l.disableSearchEngineHover()
                    } else {
                        w.isTeachingShown = false;
                        w.clearFlashSearchEngine();
                        l.hideTeaching();
                        l.hideOverlay();
                        w.setSiteStatus(true);
                        w.selectSearchEngine(x)
                    }
                });
                $("#ruyitao-functional-btns").delegate(".ruyitao-func-btn", "click", function (z) {
                    var y = $(this);
                    var x = y.attr("data-icon-id");
                    z.stopPropagation();
                    l.hidePopups();
                    switch (this.id) {
                        case "ruyitao-search-icon":
                            if (x == w.getActiveControllerIcon()) {
                                l.hideSearchBar();
                                x = null
                            } else {
                                l.showSearchBar();
                                l.focusSearch()
                            }
                            break;
                        case "ruyitao-plus-btn":
                            if (x == w.getActiveControllerIcon()) {
                                l.hideSearchEngineSetting();
                                x = null
                            } else {
                                o.renderSearchEngineSettingHtml();
                                l.showSearchEngineSetting();
                                o.setSearchEngineSettingPosition()
                            }
                            break
                    }
                    w.setActiveControllerIcon(x)
                });
                $(document).click(function (y) {
                    var x = y.target;
                    if (!$(x).is(".ruyitao-popup") && !$(x).parents(".ruyitao-popup").is(".ruyitao-popup")) {
                        w.resetPopups()
                    }
                }).keyup(function (x) {
                    if (x.keyCode == 27 && !w.isTeachingShown) {
                        if ($("#ruyitao-product-list-wrapper").is(":visible")) {
                            $("#ruyitao-search-engines .ruyitao-active-control-icon").removeClass("ruyitao-active-control-icon");
                            k.hide();
                            w.setSiteStatus(false);
                            w.setCurrentSearchEngine(null);
                            w.transparentizeControlBar();
                            l.disableSearchEngineHover()
                        } else {
                            k.show();
                            w.selectSearchEngine(w.searchEngine);
                            w.setSiteStatus(true);
                            clearTimeout(w.hideControlBarTimer);
                            l.showControlBar()
                        }
                    }
                });
                $("#ruyitao-option-link").click(function () {
                    var x = u.getURL("views/options.html");
                    u.openTab(x, true)
                });
                $("#ruyitao-search-form").submit(function (y) {
                    y.preventDefault();
                    var x = $.trim($("#ruyitao-search").val());
                    if (x) {
                        w.setKeyword(x);
                        w.selectSearchEngine(w.searchEngine);
                        u.ga({
                            category: "[" + n.i18n.getLocale() + "]SearchBox:Search",
                            action: "[Ruyitao]" + n.site.get_domain(v),
                            label: x
                        })
                    }
                })
            },
            getSiteStatus: function (w) {
                n.browser.extension.sendRequest({
                    topic: "get_site_status",
                    domain: n.site.get_site(n.site.get_domain(v))
                }, function (x) {
                    w(x)
                })
            },
            setSiteStatus: function (w) {
                n.browser.extension.sendRequest({
                    topic: "set_site_status",
                    domain: n.site.get_site(n.site.get_domain(v)),
                    status: w
                })
            },
            checkCurrentSearchEngineIsEnabled: function () {
                var x = o.getEnabled();
                var z = this.getCurrentSearchEngine();
                for (var y = 0, w = x.length; y < w; y++) {
                    if (x[y].name == z) {
                        return true
                    }
                }
                return false
            },
            selectSearchEngine: function (w) {
                this.searchEngine = w;
                var x = $("#ruyitao-se-" + w);
                if (w != q.getSearchEngine() || m != this.getKeyword()) {
                    q.doNewSearch(w, this.getKeyword());
                    o.setTitles()
                }
                var y = x.siblings(".ruyitao-active-control-icon");
                l.inactivateControlIcon(y);
                l.activateControlIcon(x);
                k.show();
                this.setCurrentSearchEngine(w);
                l.enableSearchEngineHover()
            },
            resetPopups: function () {
                l.hidePopups();
                this.setActiveControllerIcon(null)
            },
            getActiveControllerIcon: function () {
                return g
            },
            setActiveControllerIcon: function (w) {
                g = w
            },
            getCurrentSearchEngine: function () {
                return s
            },
            setCurrentSearchEngine: function (w) {
                s = w
            },
            doI18n: function () {
                var w = o.getLocale();
                var B;
                var y;
                var A;
                var x = this;
                $(".ruyitao-wrapper [data-i18n]").each(function () {
                    B = $(this).attr("data-i18n");
                    y = B.split("->");
                    A = y[1];
                    if (y[0] == "content") {
                        $(this).html(n.i18n.getMessage(A))
                    } else {
                        if (y[0] == "attribute") {
                            A = A.split(":");
                            $(this).attr(A[0], n.i18n.getMessage(A[1]))
                        }
                    }
                });
                if (w == "zh") {
                    $("#ruyitao-teaching").addClass("ruyitao-teaching-cn");
                    var z = u.getURL("assets/images/search/search-cn.png");
                    $("#ruyitao-search-icon img").attr("src", z)
                } else {
                    $("#ruyitao-teaching").addClass("ruyitao-teaching-en");
                    $("#ruyitao-help-link").hide();
                    $("#ruyitao-official-microblog-link").hide();
                    $("#ruyitao-renren-link").hide();
                    $("#ruyitao-feedback-link > a").attr("href", "http://spreadsheets.google.com/viewform?hl=en&formkey=dFhZVkE5ZC1veFk4YzRfVnpDRGtkTWc6MQ");
                    $("#ruyitao-official-website-link > a").attr("href", "http://taoassistant.com/?utm_source=ruyi&utm_medium=ext")
                }
            }
        }
    })(a, window, document);
    (function (g, i) {
        var h = i.document;
        g.ControlBar = {
            hideTimer: null,
            hideDelay: 10000,
            productsViewManager: null,
            currentProductListType: "",
            lastActiveIcon: "",
            init: function (j) {
                this.bindEvents();
                this.setPosition(j);
                if ($.browser.msie && $.browser.version == "6.0") {
                    g.IE6Patch.init()
                }
            },
            bindEvents: function () {
                var j = this;
                $("#ruyitao-controller-bar").mouseenter(function () {
                    j.clearTransparentizing()
                }).mouseleave(function () {
                    j.transparentize()
                });
                $("#ruyitao-logo").click(function (l) {
                    l.stopPropagation();
                    var k = $("#ruyitao-option-list-content");
                    if (k.is(":hidden")) {
                        k.show()
                    } else {
                        k.hide()
                    }
                });
                $("#ruyitao-functional-btns").delegate(".ruyitao-func-btn", "click", function (l) {
                    if (this.id == "ruyitao-compare-icon" && !j.isCompareEnabled()) {
                        return
                    }
                    var k = $("#ruyitao-products-wrapper");
                    var m = $("#ruyitao-price-comparation-wrapper");
                    j.activateIcon(this);
                    j.hideSearchBar();
                    j.lastActiveIcon = "";
                    switch (this.id) {
                        case "ruyitao-compare-icon":
                            if (m.is(":visible")) {
                                m.hide();
                                j.inactivateIcon(this);
                                j.lastActiveIcon = "compare"
                            } else {
                                m.show();
                                k.hide();
                                j.setPosition("product");
                                j.currentProductListType = "compare"
                            }
                            break;
                        case "ruyitao-author-icon":
                            if (k.is(":visible") && j.currentProductListType == "more_books") {
                                k.hide();
                                j.inactivateIcon(this);
                                j.lastActiveIcon = "more_books"
                            } else {
                                g.SearchBox.ProductsView.show();
                                g.SearchBox.Products.doNewSearch("amazoncn", g.ItemBar.author);
                                j.setPosition("search");
                                m.hide();
                                j.currentProductListType = "more_books"
                            }
                            break;
                        case "ruyitao-etao-icon":
                            if (k.is(":visible") && j.currentProductListType == "search_result") {
                                k.hide();
                                j.inactivateIcon(this);
                                j.lastActiveIcon = "search"
                            } else {
                                if (g.SearchBox.Products.productsData.length && j.currentProductListType == "search_result") {
                                    k.show();
                                    j.setPosition("search")
                                }
                                j.currentProductListType = "search_result";
                                m.hide();
                                j.showSearchBar();
                                $("#ruyitao-search-btn").get(0).click()
                            }
                            break
                    }
                });
                $("#ruyitao-option-link").click(function () {
                    var k = g.SearchBox.Util.getURL("views/options.html");
                    g.SearchBox.Util.openTab(k)
                });
                $("#ruyitao-search-form").click(function (k) {
                    k.stopPropagation()
                }).submit(function (l) {
                    l.preventDefault();
                    var k = $.trim($("#ruyitao-search").val());
                    if (k) {
                        g.SearchBox.ProductsView.show();
                        g.SearchBox.Products.doNewSearch("etao", k);
                        g.SearchBox.Util.ga({
                            category: "[" + g.i18n.getLocale() + "]SearchBox:Search",
                            action: "[Ruyitao]" + g.site.get_domain(h),
                            label: k
                        });
                        j.setPosition("search")
                    }
                });
                $("#ruyitao-option-list-content").click(function (k) {
                    k.stopPropagation()
                });
                $(h).click(function () {
                    $("#ruyitao-option-list-content").hide()
                }).keyup(function (m) {
                    if (m.keyCode == 27) {
                        var l = j.lastActiveIcon;
                        if (l) {
                            if (l == "compare") {
                                $("#ruyitao-price-comparation-wrapper").show();
                                j.activateIcon($("#ruyitao-compare-icon"))
                            } else {
                                if (l == "search") {
                                    j.activateIcon($("#ruyitao-etao-icon"));
                                    j.showSearchBar()
                                } else {
                                    if (l == "more_books") {
                                        j.activateIcon($("#ruyitao-author-icon"))
                                    }
                                }
                                if (g.SearchBox.Products.productsData.length) {
                                    $("#ruyitao-products-wrapper").show()
                                }
                            }
                            j.lastActiveIcon = "";
                            j.clearTransparentizing()
                        } else {
                            $("#ruyitao-products-wrapper").hide();
                            $("#ruyitao-price-comparation-wrapper").hide();
                            j.hideSearchBar();
                            var k = $("#ruyitao-functional-btns .ruyitao-active-control-icon");
                            j.inactivateIcon(k);
                            if (j.currentProductListType == "search_result") {
                                j.lastActiveIcon = "search"
                            } else {
                                if (j.currentProductListType == "more_books") {
                                    j.lastActiveIcon = "more_books"
                                } else {
                                    if (j.currentProductListType == "compare") {
                                        j.lastActiveIcon = "compare"
                                    }
                                }
                            }
                            j.transparentize()
                        }
                    }
                })
            },
            show: function () {
                if ($.browser.msie && parseInt($.browser.version) < 9) {
                    $("#ruyitao-controller-bar").css("filter", "")
                } else {
                    $("#ruyitao-controller-bar").css("opacity", 1)
                }
            },
            transparentize: function () {
                if ($("#ruyitao-products-wrapper").is(":hidden") && $("#ruyitao-price-comparation-wrapper").is(":hidden")) {
                    this.hideTimer = setTimeout(function () {
                        $("#ruyitao-controller-bar").css("opacity", 0.3)
                    }, this.hideDelay)
                }
            },
            clearTransparentizing: function () {
                clearTimeout(this.hideTimer);
                this.show()
            },
            CONTROL_BAR_BOTTOM_WITH_PRICE_COMPARATION: 50,
            CONTROL_BAR_BOTTOM_WITH_SEARCH: 80,
            setPosition: function (j) {
                if ($.browser.msie && $.browser.version == "6.0") {
                    var m = j == "product" ? this.CONTROL_BAR_BOTTOM_WITH_PRICE_COMPARATION : this.CONTROL_BAR_BOTTOM_WITH_SEARCH;
                    g.IE6Patch.setBarPosition(m);
                    g.IE6Patch.resetPosition()
                } else {
                    var l = "ruyitao-" + j + "-bottom";
                    var k = j == "product" ? "ruyitao-search-bottom" : "ruyitao-product-bottom";
                    $("#ruyitao-controller-bar").addClass(l).removeClass(k)
                }
            },
            showSearchBar: function () {
                $("#ruyitao-search-bar").show();
                $("#ruyitao-search").get(0).focus()
            },
            hideSearchBar: function () {
                $("#ruyitao-search-bar").hide()
            },
            activateIcon: function (k) {
                var j = "ruyitao-active-control-icon";
                $(k).siblings(".ruyitao-func-btn").removeClass(j).end().addClass(j)
            },
            inactivateIcon: function (j) {
                $(j).removeClass("ruyitao-active-control-icon")
            },
            hideCompareIcon: function () {
                $("#ruyitao-compare-icon").hide()
            },
            compareEnabled: true,
            disableCompareIcon: function () {
                this.compareEnabled = false;
                var j = g.SearchBox.Util.getURL("assets/images/products/compare-disabled.png");
                $("#ruyitao-compare-icon").css("cursor", "default").attr("title", "\u6682\u65e0\u7cbe\u786e\u6bd4\u4ef7\u6570\u636e").find("img").attr("src", j)
            },
            isCompareEnabled: function () {
                return this.compareEnabled
            },
            hideAuthorIcon: function () {
                $("#ruyitao-author-icon").hide()
            },
            setKeyword: function (j) {
                $("#ruyitao-search").val(j)
            }
        }
    })(a, window);
    (function (n, j) {
        var g = j.site;
        var u = j.browser.extension;
        var t = n.document;
        var s = j.SearchBox.Util;

        function h() { }
        function p(z) {
            var w, x, y = z.length,
                B, A;
            for (; y--; ) {
                B = z[y];
                x = $(B.xpath);
                A = new RegExp(B.regexp, "i");
                $.each(x, function () {
                    var D = this.innerHTML || "",
                        C;
                    if ((C = D.match(A))) {
                        w = C[1];
                        return false
                    }
                })
            }
            return w
        }
        function v(w) {
            var y, x = {};
            if (!w) {
                return
            }
            for (y in w) {
                if (w.hasOwnProperty(y)) {
                    x[y] = p(w[y])
                }
            }
            h(x);
            return x
        }
        j.shareWeibo = function (A) {
            var z = encodeURIComponent,
                w = window.screen,
                y = [],
                x = "http://v.t.sina.com.cn/share/share.php?";
            for (name in A) {
                if (A.hasOwnProperty(name)) {
                    y.push(name + "=" + z(A[name]))
                }
            }
            y.push("appkey=1965387856");
            x += y.join("&");
            window.open(x, "mb", ["toolbar=0,status=0,resizable=1,width=620,height=450,left=", (w.width - 620) / 2, ",top=", (w.height - 450) / 2].join(""))
        };
        var o = 20;
        var r = 76;
        var m = 106;
        var q = 2;
        var i = 20;
        var l = j.PriceComparationsUI = {
            viewPortWidth: 0,
            init: function (x) {
                this.viewPortWidth = document.documentElement.clientWidth;
                var w = this.calcMarketNumByViewPortWidth(x);
                this.setMarketListWrapperWIdthByMarketNum(w);
                this.bindEvents()
            },
            bindEvents: function () {
                var w = this;
                $(window).resize(j.debounce(function () {
                    if (document.documentElement.clientWidth != w.viewPortWidth) {
                        w.viewPortWidth = document.documentElement.clientWidth;
                        var x = w.calcMarketNumByViewPortWidth(j.ItemBar.productNum);
                        w.setMarketListWrapperWIdthByMarketNum(x)
                    }
                }))
            },
            setMarketListWidth: function (w) {
                $("#ruyitao-market-list").width(w)
            },
            calcMarketNumByViewPortWidth: function (x) {
                var z = document.documentElement.clientWidth;
                var y = z - o - o - m;
                var w = Math.floor(y / r);
                if (w > x) {
                    w = x
                }
                if (w < q) {
                    w = q
                } else {
                    if (w > i) {
                        w = i
                    }
                }
                return w
            },
            setMarketListWrapperWIdthByMarketNum: function (w) {
                var x = r * w;
                this.setMarketListWidth(x)
            },
            show: function () {
                $("#ruyitao-price-comparation-wrapper").show()
            },
            hide: function () {
                $("#ruyitao-price-comparation-wrapper").hide()
            }
        };
        j.ItemBar = {
            _max_items: f,
            _loading: false,
            _page_size: f,
            _total_pages: f,
            _page: 0,
            _has_more_books: false,
            moreBooksOfAuthor: null,
            productNum: 0,
            initPriceComparation: function (x) {
                var w = this;
                var y = x.productList;
                this.productNum = y.length;
                this.getTemplate(function (z) {
                    $(document.body).append(z);
                    j.SearchBox.Products.init();
                    j.SearchBox.ProductsView.init();
                    w.renderMarketList(y);
                    var A = y.length;
                    if (x._max_items) {
                        A = Math.min(A, w._max_items)
                    }
                    l.init(A);
                    l.show();
                    j.ControlBar.init("product");
                    j.ControlBar.hideSearchBar();
                    j.ControlBar.activateIcon($("#ruyitao-compare-icon"));
                    j.ControlBar.show();
                    j.ControlBar.currentProductListType = "compare";
                    w.bindEvents(x.product);
                    w.checkMoreBooksOfAuthor(x.book_author);
                    s.sendLog("show", document.location.href);
                    s.handleSogou()
                })
            },
            initSearch: function (x) {
                var w = this;
                this.getTemplate(function (y) {
                    $(document.body).append(y);
                    j.SearchBox.Products.init();
                    j.SearchBox.ProductsView.init();
                    j.ControlBar.init("search");
                    j.ControlBar.show();
                    j.ControlBar.activateIcon($("#ruyitao-etao-icon"));
                    j.ControlBar.showSearchBar();
                    j.ControlBar.hideAuthorIcon();
                    j.ControlBar.disableCompareIcon();
                    j.ControlBar.setKeyword(x);
                    j.SearchBox.ProductsView.show();
                    j.SearchBox.Products.doNewSearch("etao", x);
                    j.ControlBar.currentProductListType = "search_result";
                    s.sendLog("show", document.location.href);
                    s.handleSogou()
                })
            },
            getTemplate: function (w) {
                u.sendRequest({
                    topic: "get_template",
                    page: "views/products.html"
                }, w)
            },
            bindEvents: function (x) {
                $("#ruyitao-market-list").delegate(".ruyitao-market-item", "click", function () {
                    var y = $(this).attr("data-href");
                    s.openTab(y);
                    s.sendLog("click", y)
                });
                $("#ruyitao-more-results-link").click(function () {
                    j.SearchBox.Util.openTab(x.DetailPageURL, true)
                });
                var w = {
                    url: x.DetailPageURL,
                    title: "\u6bd4\u4ef7\uff0c\u76f4\u63a5\u70b9\uff01\u6211\u521a\u7528@\u5982\u610f\u6dd8 \u67e5\u4e86\u300a" + x.Title + "\u300b\uff08#\u5982\u610f\u6dd8\u6bd4\u4ef7#\uff09"
                };
                if (x.SmallImageUrl) {
                    w.pic = x.SmallImageUrl.replace("_80x80.jpg", "")
                }
                $("#ruyitao-forward-link").click(function () {
                    j.shareWeibo(w)
                })
            },
            renderMarketList: function (w) {
                var y = $("#ruyitao-market-item-template").html();
                $.each(w, function (z, A) {
                    A.DetailUrl = A.ClickUrl || A.DetailPageURL
                });
                var x = j.SearchBox.Tmpl.getMarketsTemplate(w);
                $("#ruyitao-market-list").html(x)
            },
            fillMoreBookList: function (B) {
                var B = this.moreBooksOfAuthor;
                if (B) { }
                var A = $("#ruyitao-book-list");
                var z = 0;
                var w = Math.min(B.length, 6);
                var x = [];
                for (z; z < w; z++) {
                    var y = B[z];
                    x.push('<li class="ruyitao-book-item">');
                    x.push('<a target="_blank" href="' + (y.ClickUrl || y.DetailPageURL) + '">' + y.Title + "</a>");
                    x.push("</li>");
                    if (z != w - 1) {
                        x.push('<li class="ruyitao-book-separater"></li>')
                    }
                }
                A.html(x.join(""))
            },
            checkMoreBooksOfAuthor: function (w) {
                if (!w) {
                    j.ControlBar.hideAuthorIcon();
                    return
                }
                j.console.debug("Has author: " + w);
                u.sendRequest({
                    topic: "item_search",
                    Keyword: w,
                    SearchEngine: "amazoncn",
                    ItemPage: 1
                }, function (x) {
                    if (typeof x.Items == "object" && x.Items.length > 0) {
                        j.console.debug(w + " wroted " + x.Items.length + " books.");
                        j.ItemBar._has_more_books = true;
                        j.ItemBar.moreBooksOfAuthor = x.Items;
                        j.ItemBar.author = w
                    } else {
                        j.ControlBar.hideAuthorIcon()
                    }
                })
            }
        };
        var k = function (w) {
            return JSON.stringify({
                url: n.location.href,
                title: n.document.title,
                isbn: w
            })
        };
        j.sameBookAssist = {};
        j.sameBookAssist.run = function (y) {
            var x = g.get_url(t);
            var z = g.get_domain(t);
            var w = this;
            u.sendRequest({
                topic: "is_book_site",
                domain: z,
                url: x
            }, function (B) {
                if (!B) {
                    y.run();
                    return
                }
                if (typeof j.loadJQuery == "function") {
                    $ = j.loadJQuery()
                }
                var C = v(B);
                if (C.isbn) {
                    var A = k(C.isbn);
                    j.browser.extension.sendRequest({
                        topic: "item_search",
                        Keyword: A,
                        SearchEngine: "product_search",
                        ItemPage: 1
                    }, function (D) {
                        if (typeof D.Items == "object" && D.Items.length > 0) {
                            j.ItemBar.initPriceComparation({
                                productList: D.Items,
                                max_items: 8,
                                book_author: C.author,
                                product: D.Product
                            })
                        }
                    })
                } else {
                    y.run()
                }
            })
        }
    })(window, a);
    (function (i, g) {
        var h = function () {
            return JSON.stringify({
                url: i.location.href,
                title: i.document.title
            })
        };
        g.productSearch = {};
        g.productSearch.run = function (k) {
            var j = this;
            g.browser.extension.sendRequest({
                topic: "is_detail_site",
                url: i.location.href,
                title: i.document.title
            }, function (l) {
                if (typeof l.locale != "undefined") {
                    var m;
                    if (typeof g.loadJQuery == "function") {
                        $ = g.loadJQuery()
                    }
                    if (l.product) {
                        m = h();
                        g.browser.extension.sendRequest({
                            topic: "item_search",
                            Keyword: m,
                            SearchEngine: "product_search",
                            ItemPage: 1
                        }, function (n) {
                            if (typeof n.Items == "object" && n.Items.length > 0) {
                                g.ItemBar.initPriceComparation({
                                    productList: n.Items,
                                    product: n.Product
                                })
                            }
                        })
                    } else {
                        if (l.keyword) {
                            g.ItemBar.initSearch(l.keyword)
                        }
                    }
                }
            })
        }
    })(window, a);
    (function (j, m) {
        var h = {
            "x-webkit-speech": "",
            lang: "zh-CN",
            "x-webkit-grammar": "builtin:translate"
        };
        var l = {
            "taobao.com": ["#title", "#title2"],
            "tmall.com": ["#mq", "#btm-mq"],
            "360buy.com": ["#key", "#key-re-search", "#keyword"],
            "suning.com": ["#searchKeywords"],
            "amazon.cn": ["#twotabsearchtextbox"],
            "coo8.com": ["#searchKeywords", "#searchKeywords2"],
            "51buy.com": ["#q_show"]
        };
        var k = j.site.get_domain(m);
        var g = j.site.get_site(k);
        var i;
        if (g in l) {
            i = l[g];
            $.each(i, function (o, n) {
                $(n).attr(h)
            })
        }
    })(a, document);
    var b = new c.filterChain(c.SearchBox.App, c.sameBookAssist, c.productSearch);
    b.run()
})(window, exports);